#!/usr/bin/env python
# -*- coding:utf-8 -*-
###
# Filename: /Users/simonliu/Documents/Haas/pythonprojects/solutions/haas100_oled/main.py
# Path: /Users/simonliu/Documents/Haas/pythonprojects/solutions/haas100_oled
# Created Date: Tuesday, October 26th 2021, 11:33:39 am
# Author: Simon Liu
# 
# Copyright (C) <2021>  <刘知海> <toopoo@gmail.com> GPLv3
 
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
 
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <https://www.gnu.org/licenses/>.
###
# -*- coding: UTF-8 -*-
import time
from driver import SPI
from driver import GPIO
import sh1106

# OLED屏幕实例
oled = None

def oled_init():
    oled_spi = SPI()
    oled_spi.open("SPI0")

    oled_res = GPIO()
    oled_res.open("oled_res")

    oled_dc = GPIO()
    oled_dc.open("oled_dc")
    global oled
    oled = sh1106.SH1106_SPI(128, 64, oled_spi, oled_dc, oled_res)

def hello():
    global oled
    oled.fill(0)
    oled.text(' Hello HaaS100!', 2, 16, 1)
    oled.text('    Simon Liu', 2, 32, 1)
    oled.show()
    

def main():
    print("---=== OLED example ===---")
    oled_init()
    hello()
    

if __name__ == '__main__':
    main()